package com.yixun.qfbao.hander;

import com.yixun.qfbao.api.service.ThirdPartyApiService;
import com.yixun.qfbao.apidto.*;
import com.yixun.qfbao.dto.base.BaseRequestDTO;
import com.yixun.qfbao.dto.base.BaseResponseDTO;
import com.yixun.qfbao.enums.QfSmsTemplateEnum;
import com.yixun.qfbao.hander.base.CommonAbstractHander;
import com.yixun.qfbao.model.Company;
import com.yixun.qfbao.model.dto.CompanyDto;
import com.yixun.qfbao.model.dto.SmsHistoryDto;
import com.yixun.qfbao.model.enums.DelFlagEnum;
import com.yixun.qfbao.model.enums.SMSTypeEnum;
import com.yixun.qfbao.model.enums.SendStatusEnum;
import com.yixun.qfbao.service.SmsHistoryService;
import com.yixun.qfbao.util.exception.TServerException;
import com.yixun.qfbao.vo.SendMobileCheckCodeReqVo;
import com.yixun.qfbao.vo.SendValidateCodeForPwdReqVo;
import com.yixun.qfbao.xf.model.enums.ResultEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @Description
 * @Date 2020-5-26
 * @Author jhosng
 * @Computer Administrator
 */
@Service("sendMobileCheckCodeHander")
public class SendMobileCheckCodeHander extends CommonAbstractHander {
    private static Logger logger= LoggerFactory.getLogger(SendMobileCheckCodeHander.class);

    @Autowired
    private ThirdPartyApiService thirdPartyApiService;
    @Autowired
    private SmsHistoryService smsHistoryService;

    @Override
    public BaseResponseDTO doBusiness(BaseRequestDTO reqDto) {
        SendMobileCheckCodeReqVo req = (SendMobileCheckCodeReqVo)reqDto;
        SendMobileCheckCodeReqDto reqDto1 = req.getParams();
        BaseResponseDTO<SendMobileCheckCodeResDto> res = new BaseResponseDTO<>();
        SendMobileCheckCodeResDto resDto = new SendMobileCheckCodeResDto();
        try {
            resDto = thirdPartyApiService.sendMobileCheckCode(reqDto1);
        } catch (TServerException e){
            resDto.setResult(ResultEnum.FAIL.getNo());
            resDto.setResultMsg(e.getMessage());
        }
        catch (Exception e) {
            logger.error("SendValidateCodeForPwdHander error: {}", e);
            resDto.setResult(ResultEnum.FAIL.getNo());
            resDto.setResultMsg("发送失败!");
        }
        res.setResData(resDto);
        res.setResult(resDto.getResult());
        res.setErrorMsg(resDto.getResultMsg());
        return res;
    }
}
